unit authorization;

interface
 function RunAuth(var Str: String): boolean;
implementation
uses windows,classes,SysUtils;
function RunAuth(var Str: String): boolean;
var
   I: byte;
   S: string;
   Flag: boolean;
   tRead, cWrite, dwRead, dwAvail: cardinal;
   SA: TSecurityAttributes;
   PI: TProcessInformation;
   SI: TStartupInfo;
begin
   Result:=False;
   SA.nLength:=SizeOf(SECURITY_ATTRIBUTES);
   SA.bInheritHandle:=True;
   SA.lpSecurityDescriptor:=nil;
   if not CreatePipe(tRead, cWrite, @SA, 0) then Exit;
   ZeroMemory(@SI, SizeOf(TStartupInfo));
   SI.cb:=SizeOf(TStartupInfo);
   SI.dwFlags:=STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
   SI.wShowWindow:=SW_HIDE;
   SI.hStdOutput:=cWrite;
   if CreateProcess(nil, PChar('auth.exe -a'), nil, nil, True, 0, nil, nil, SI, PI) then begin
   WaitForSingleObject(Pi.hProcess,INFINITE);
CloseHandle(PI.hProcess);
      CloseHandle(PI.hThread);
     // Str.Clear();
      Flag:=True;
      while Flag do begin
         for I:=0 to 9 do begin
            PeekNamedPipe(tRead, nil, 0, nil, @dwAvail, nil);
            if (dwAvail>0) then begin
               Flag:=True;
               Break;
            end
            else Flag:=False;
            Sleep(100);
         end; //for I:=
         if dwAvail>0 then begin
            SetLength(S, dwAvail);
            ReadFile(tRead, PChar(S)^, Length(S), dwRead, Nil);
            OemToChar(PChar(S), PChar(S));
            Str:=str+s;
            //Application.ProcessMessages;
            Result:=True;
         end; // if dwAvail
      end;    // while Flag
   end;       // if CreateProcess
end;




end.
